package org.ragdollcat.secondaiagent.rag;


import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * spring ai内置的基于内存的向量数据库
 */
@Configuration
public class VectorStoreConfig {

    @Autowired
    private DocumentLoader documentLoader;

    @Resource
    private MyKeywordEnricher myKeywordEnricher;

    @Resource
    private MySummaryEnricher mySummaryEnricher;

    @Bean
    public VectorStore vectorStore(EmbeddingModel dashScopeEmbeddingModel){
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashScopeEmbeddingModel)
                .build();
        //加载文档
        List<Document> document = documentLoader.getDocument();
        // 摘要元数据增强器
//        List<Document> documents = mySummaryEnricher.enrichDocuments(document);
        //存入向量数据库
        simpleVectorStore.doAdd(document);
        return simpleVectorStore;
    }
}
